home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Arashi 1.1.1 / source code / Game Source / jam src / STDemoMode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-09  |  3.5 KB  |  185 lines  |  [TEXT/KAHL]

  1. /*/
  2.      Project Arashi: STDemoMode.c
  3.      Major release: Version 1.1d2, 9/5/95
  4.  
  5.      Last modification: Wednesday, September 9, 1992, 21:44
  6.      Created: Tuesday, January 15, 1991, 20:56
  7.  
  8.      Copyright © 1991-1992, Juri Munkki
  9. /*/
  10.  
  11. #include "VA.h"
  12. #include "Storm.h"
  13.  
  14. #define    GONSIDES    10
  15.  
  16. extern    EventRecord    Event;
  17.  
  18. /*    Demo modes:
  19. */
  20. enum    {    Entering, Rotating, Exiting, Ended    };
  21.  
  22. static    int        demomode;
  23. static    int        distance;
  24. static    int        pentalevel;
  25. static    int        centerlevel;
  26. static    int        subgonlevel;
  27.  
  28. static    Point    penta[GONSIDES+1];
  29. static    Point    subpenta[GONSIDES/2];
  30. static    int        behindflag[GONSIDES];
  31. static    int        baseangle=0;
  32. static    int        centerx,centery;
  33.  
  34. int        titlescale;
  35.  
  36. void    CalcGonSides()
  37. {
  38.     int        i,angle;
  39.     int        x,y;
  40.     
  41.     angle=baseangle;
  42.     for(i=0;i<GONSIDES;i++)
  43.     {    x=Cosins[angle];
  44.         y=Sins[angle]+distance;
  45.         
  46.         behindflag[i]=(y>distance);
  47.         penta[i].h=centerx+(x*(long)titlescale)/y;
  48.         penta[i].v=centery+(pentalevel*(long)titlescale)/y;
  49.         angle+=ANGLES/GONSIDES;
  50.         if(angle>=ANGLES) angle-=ANGLES;
  51.     }
  52.     
  53.     penta[GONSIDES].h=centerx;
  54.     penta[GONSIDES].v=centery+(centerlevel*(long)titlescale)/distance;
  55.     
  56.     angle=baseangle+ANGLES/GONSIDES;
  57.     for(i=0;i<GONSIDES/2;i++)
  58.     {    angle+=ANGLES/(GONSIDES/2);
  59.         if(angle>=ANGLES) angle-=ANGLES;
  60.  
  61.         x=Cosins[angle]/3;
  62.         y=(Sins[angle]/3)+distance;
  63.  
  64.         subpenta[i].h=centerx+(x*(long)titlescale)/y;
  65.         subpenta[i].v=centery+(subgonlevel*(long)titlescale)/y;
  66.     }
  67.  
  68.     baseangle+= 1;
  69.     if(baseangle>=ANGLES) baseangle-=ANGLES;
  70. }
  71.  
  72. void    DrawMainGon()
  73. {
  74.     int        i;
  75.     
  76.     VA.color=5;
  77.     VAMoveTo(penta[GONSIDES-1].h,penta[GONSIDES-1].v);
  78.     for(i=0;i<GONSIDES;i++)
  79.     {    VASafeLineTo(penta[i].h,penta[i].v);
  80.     }
  81.     
  82.     VAMoveTo(penta[0].h,penta[0].v);
  83.     for(i=0;i<GONSIDES*2+2;i+=4)
  84.     {    VASafeLineTo(penta[i%GONSIDES].h,penta[i%GONSIDES].v);
  85.     }
  86.     
  87.     for(i=0;i<GONSIDES;i+=2)
  88.     {    if(behindflag[i])
  89.         {    VA.color=0;
  90.         }
  91.         else
  92.         {    VA.color=5;
  93.         }
  94.         
  95.         if(Event.modifiers & optionKey)
  96.         {    VAFractalLine(penta[GONSIDES].h,penta[GONSIDES].v,penta[i].h,penta[i].v,1<<7,3);
  97.         }
  98.         else
  99.         {    VAMoveTo(penta[GONSIDES].h,penta[GONSIDES].v);
  100.             VASafeLineTo(penta[i].h,penta[i].v);
  101.         }
  102.     }
  103. }
  104.  
  105. void    DrawSubGon(color)
  106. int        color;
  107. {
  108.     int        i;
  109.  
  110.     VA.color=color;
  111.     VAMoveTo(subpenta[GONSIDES/2-1].h,subpenta[GONSIDES/2-1].v);
  112.     for(i=0;i<GONSIDES/2;i++)
  113.     {    VASafeLineTo(subpenta[i].h,subpenta[i].v);
  114.     }
  115. }
  116. void    DemoMode()
  117. {
  118.     VAEraseBuffer();
  119.     VAInitFractalLines();
  120.  
  121.     centerx=(VA.frame.right-VA.frame.left)/2;
  122.     centery=(VA.frame.bottom-VA.frame.top)/2;
  123.  
  124.     if(centerx>centery)    titlescale=centery;
  125.     else                titlescale=centerx;
  126.         
  127.     demomode=Entering;
  128.     distance=8000;
  129.     pentalevel=150;
  130.     centerlevel=-300;
  131.     subgonlevel=10000;
  132.     
  133.     do
  134.     {    if(!GetNextEvent(everyEvent,&Event))    Event.what=0;
  135.         switch(Event.what)
  136.         {    case keyDown:
  137.                 subgonlevel=pentalevel;
  138.                 break;
  139.             case mouseDown:
  140.                 PlayA(Blast,100);
  141.                 PlayB(Blast,100);
  142.                 if(demomode==Rotating)
  143.                     demomode=Exiting;
  144.                 else
  145.                     demomode=Ended;
  146.                 break;
  147.         }
  148.         
  149.         switch(demomode)
  150.         {    case Entering:
  151.                 distance-=75;
  152.                 if(distance<500)
  153.                 {    distance=500;
  154.                     demomode=Rotating;
  155.                 }
  156.                 break;
  157.             case Rotating:
  158.                 break;
  159.             case Exiting:
  160.                 pentalevel=pentalevel*3/4;
  161.                 centerlevel=centerlevel*3/4;
  162.                 if(pentalevel<=centerlevel)
  163.                     demomode=Ended;
  164.                 break;
  165.         }
  166.                 
  167.         CalcGonSides();
  168.         DrawMainGon();
  169.         
  170.         GlobalToLocal(&Event.where);
  171.         VA.color=4;
  172.         VAFractalLine(penta[GONSIDES].h,penta[GONSIDES].v,Event.where.h,Event.where.v,1<<7,5);
  173.         
  174.         if(subgonlevel<=pentalevel)
  175.         {    DrawSubGon(2);
  176.             subgonlevel-=10;
  177.             if(subgonlevel<-400)
  178.                 subgonlevel=10000;
  179.         }
  180.  
  181.         VAStep();
  182.     }    while(demomode!=Ended);
  183.     
  184.     VACloseFractalLines();
  185. }